﻿function Salvar() {
	alert("Cliente Incluido com Sucesso!");
}

function Sair() {
	window.location = "home.jsp";
}

function ExpandeMinimizaFieldset(tblFdset, img) {
	if (document.getElementById(tblFdset).style.display == "none") {
		document.getElementById(tblFdset).style.display = "table";
		document.getElementById(img).src = "resources/img/Botoes/recolher.png";
		document.getElementById(img).title = 'Ocultar Detalhes';
	} else {
		document.getElementById(tblFdset).style.display = "none";
		document.getElementById(img).src = "resources/img/Botoes/expandir.png";
		document.getElementById(img).title = 'Mostrar Detalhes';
	}
}

function abrirPopUpNew(URL, width, height) {

	var left = (screen.width / 2) - (width / 2);
	var top = (screen.height / 2) - (height / 2);

	window
			.open(
					URL,
					'janela',
					'width='
							+ width
							+ ', height='
							+ height
							+ ', top='
							+ top
							+ ', left='
							+ left
							+ ', scrollbars=yes, status=no, toolbar=no, location=no, directories=no, menubar=no, resizable=no, fullscreen=no');

}

function montaCssTabela() {

	var objTbl = document.getElementById("Tabela");

	var cont = 2;

	for (cont; cont < objTbl.rows.length; cont++) {

		if (cont % 2 != 0) {
			objTbl.rows[cont].className = "TabDet";
		} else {
			objTbl.rows[cont].className = "TabDetAlter";
		}

	}
}

function montaCssTabelaCupom() {

	var objTbl = document.getElementById("Tabela");

	var cont = 3;

	for (cont; cont < objTbl.rows.length; cont++) {

		if (cont % 2 != 0) {
			objTbl.rows[cont].className = "TabDet";
		} else {
			objTbl.rows[cont].className = "TabDetAlter";
		}

	}
}

function MudaTipoCliente(obj) {
	if (obj.id == 'rdPF') {
		document.getElementById("Linha2").style.display = "table-row";
		document.getElementById("Linha3").style.display = "table-row";
		document.getElementById("Linha4").style.display = "none";
		document.getElementById("Linha5").style.display = "none";
		limpaCamposCliente2(obj);
	}

	if (obj.id == 'rdPJ') {

		document.getElementById("Linha2").style.display = "none";
		document.getElementById("Linha3").style.display = "none";
		document.getElementById("Linha4").style.display = "table-row";
		document.getElementById("Linha5").style.display = "table-row";
		limpaCamposCliente2(obj);
	}
}

function MudaTipoCliente2(obj) {
	var objTbl = document.getElementById("Tabela");
	if (obj.id == 'rdPF') {
		objTbl.style.display = "none";
		document.getElementById("Linha3").style.display = "table-row";
		document.getElementById("Linha4").style.display = "table-row";
		document.getElementById("Linha5").style.display = "none";
		document.getElementById("Linha6").style.display = "none";
		limpaCamposCliente(obj);
	}

	if (obj.id == 'rdPJ') {
		objTbl.style.display = "none";
		document.getElementById("Linha3").style.display = "none";
		document.getElementById("Linha4").style.display = "none";
		document.getElementById("Linha5").style.display = "table-row";
		document.getElementById("Linha6").style.display = "table-row";
		limpaCamposCliente(obj);
	}
}

function limpaCamposCliente(obj) {
	document.getElementById("txtCodCliente").value = '';
	if (obj.id == 'rdPJ') {

		document.getElementById("NomePF").value = '';
		document.getElementById("RG").value = '';
		document.getElementById("CPF").value = '';

	}
	if (obj.id == 'rdPF') {
		document.getElementById("NomePJ").value = '';
		document.getElementById("CNPJ").value = '';
		document.getElementById("IM").value = '';
	}
}

function limpaCamposCliente2(obj) {
	if (obj.id == 'rdPJ') {

		document.getElementById("NomePF").value = '';
		document.getElementById("RG").value = '';
		document.getElementById("CPF").value = '';

	}
	if (obj.id == 'rdPF') {
		document.getElementById("NomePJ").value = '';
		document.getElementById("CNPJ").value = '';
		document.getElementById("IM").value = '';
	}
}

function preencheTipoCliente(tipo) {
	document.getElementById("hdnTipoCliente").value = tipo;

}

function valAlfaNumerico() {
	if ((!(event.keyCode >= 48 && event.keyCode <= 57)) // Se não for
			// numeros
			&& (!(event.keyCode >= 97 && event.keyCode <= 122))// E nao for
																// letra
			// minuscula
			&& (!(event.keyCode >= 65 && event.keyCode <= 90)) // E nao for
																// letra
			// maiuscula
			&& event.keyCode != 8 && event.keyCode != 46 // E nao for
															// backspace
			&& event.keyCode != 32 && event.keyCode != 42 // Asterisco
	)
		event.returnValue = false;

}

function ValidaAlfaNumerico() {
	if ((!(event.keyCode >= 48 && event.keyCode <= 57)) // Se não for
			// numeros
			&& (!(event.keyCode >= 97 && event.keyCode <= 122))// E nao for
																// letra
			// minuscula
			&& (!(event.keyCode >= 65 && event.keyCode <= 90)) // E nao for
																// letra
	// maiuscula
	) {
		event.returnValue = false;
		return false;
	}
}

function ExpandeFieldset(tbls, imgTbls) {
	for ( var i = 0; i < tbls.length; i++) {
		if (document.getElementById(tbls[i]).style.display == "none") {
			document.getElementById(tbls[i]).style.display = "table";
			document.getElementById(imgTbls[i]).src = "resources/img/Botoes/recolher.png";
			document.getElementById(imgTbls[i]).title = 'Ocultar Detalhes';

		}

	}
}

function Submita(submit) {
	document.getElementById(submit).click();
}

function EscondeBotaoExcluir(obj) {
	if (document.getElementById(obj).style.display = "block") {

		document.getElementById(obj).style.display = "none";
	}
}